package com.jwinf.cdLibary.controller;

import com.jwinf.cdLibary.tool.WindowUtils;

import java.sql.SQLException;

/**
 * @author jwinf
 * 添加cd窗口控制类
 */
public class AddCdFrameController extends OperateCdFrameController{

    // 重写提交方法 实现添加操作
    @Override
    protected void submit() throws SQLException {
        // 获取组件中的数据
        String code = codetxt.getText();
        String name = nametxt.getText();
        String sort = sorttxt.getText();
        String number = numbertxt.getText();

        //验证数据
        if(!check(code, "名称为空") || !check(name, "名称为空") || !check(sort, "分类为空") || !check(number, "数量为空")){
            return;
        }

        // 给cd对象设置数据
        cd.setCode(code);
        cd.setName(name);
        cd.setSort(sort);
        cd.setNumber(Integer.parseInt(number));

        // 调用服务层的添加方法
        if(cdService.add(cd)){
            // 使用工具类跳出弹窗提示用户
            WindowUtils.showTip("添加成功", "/icon/SuccessIcon.png", "-fx-background-color:  linear-gradient(to top, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);");
        }else {
            WindowUtils.showTip("添加失败", "/icon/warnIcon.png", "-fx-background-color:  linear-gradient(to top, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);");
        }
    }
}
